var Fs = require( "fs" );
var images = Fs.readdirSync( "images" );
var template = Fs.readFileSync( "tools/template.less" ).toString();
var size = "20px";
var image, emojiName, temp;
var output = "";
var a = [];
for ( var i = 0; i < images.length; i++ ) {
  image = images[i];
  
  // Deal with images which doesn't start with a dot (OS files)
  if ( !(/^[^\.]/.test( image )) ) {
    continue;
  }
  emojiName = image.split( "." )[0];
  a.push(emojiName);

  temp = "";
  temp = template.replace( /@emoji-path/g, image );
  temp = temp.replace( /@emoji/g, emojiName );
  temp = temp.replace( /@size/g, size );

  output += temp;
}
var emojisData = [
    {"key": "aini", "name": "爱你"},
    {"key": "am", "name": "傲慢"},
    {"key": "baiy", "name": "白眼"},
    {"key": "bb", "name": "便便"},
    {"key": "bq", "name": "抱拳"},
    {"key": "bs", "name": "鄙视"},
    {"key": "bu", "name": "NO"},
    {"key": "bye", "name": "再见"},
    {"key": "bz", "name": "闭嘴"},
    {"key": "cd", "name": "菜刀"},
    {"key": "ch", "name": "擦汗"},
    {"key": "clap", "name": "鼓掌"},
    {"key": "cool", "name": "得意"},
    {"key": "cy", "name": "呲牙"},
    {"key": "dao", "name": "刀"},
    {"key": "db", "name": "大兵"},
    {"key": "dg", "name": "蛋糕"},
    {"key": "dk", "name": "大哭"},
    {"key": "fad", "name": "发抖"},
    {"key": "fd", "name": "发呆"},
    {"key": "fendou", "name": "奋斗"},
    {"key": "fn", "name": "发怒"},
    {"key": "fw", "name": "飞吻"},
    {"key": "gg", "name": "尴尬"},
    {"key": "gift", "name": "礼物"},
    {"key": "gy", "name": "勾引"},
    {"key": "hanx", "name": "憨笑"},
    {"key": "heart", "name": "心碎"},
    {"key": "hq", "name": "哈欠"},
    {"key": "hsh", "name": "投降"},
    {"key": "ht", "name": "回头"},
    {"key": "hug", "name": "拥抱"},
    {"key": "jd", "name": "跳绳"},
    {"key": "jie", "name": "饥饿"},
    {"key": "jk", "name": "惊恐"},
    {"key": "jy", "name": "惊讶"},
    {"key": "ka", "name": "愉快"},
    {"key": "kb", "name": "抠鼻"},
    {"key": "kel", "name": "可怜"},
    {"key": "kf", "name": "咖啡"},
    {"key": "kiss", "name": "亲亲"},
    {"key": "kkl", "name": "快哭了"},
    {"key": "kl", "name": "骷髅"},
    {"key": "kt", "name": "磕头"},
    {"key": "kuk", "name": "酷"},
    {"key": "kun", "name": "困"},
    {"key": "ladybug", "name": "瓢虫"},
    {"key": "lengh", "name": "冷汗"},
    {"key": "lips", "name": "嘴唇"},
    {"key": "love", "name": "爱情"},
    {"key": "lq", "name": "篮球"},
    {"key": "meigui", "name": "玫瑰"},
    {"key": "ng", "name": "难过"},
    {"key": "oh", "name": "怄火"},
    {"key": "ok", "name": "OK"},
    {"key": "peace", "name": "胜利"},
    {"key": "pig", "name": "猪头"},
    {"key": "pinky", "name": "差劲"},
    {"key": "pj", "name": "啤酒"},
    {"key": "pp", "name": "乒乓"},
    {"key": "pz", "name": "撇嘴"},
    {"key": "qd", "name": "糗大了"},
    {"key": "qiang", "name": "强"},
    {"key": "qiao", "name": "敲打"},
    {"key": "rice", "name": "饭"},
    {"key": "ruo", "name": "弱"},
    {"key": "se", "name": "色"},
    {"key": "shd", "name": "闪电"},
    {"key": "shuai", "name": "衰"},
    {"key": "shy", "name": "害羞"},
    {"key": "sleep", "name": "睡"},
    {"key": "smile", "name": "微笑"},
    {"key": "sun", "name": "太阳"},
    {"key": "tiao", "name": "跳跳"},
    {"key": "trick", "name": "坏笑"},
    {"key": "tu", "name": "吐"},
    {"key": "tx", "name": "偷笑"},
    {"key": "wilt", "name": "凋谢"},
    {"key": "wq", "name": "委屈"},
    {"key": "ws", "name": "握手"},
    {"key": "xia", "name": "吓"},
    {"key": "xigua", "name": "西瓜"},
    {"key": "xu", "name": "嘘"},
    {"key": "yhh", "name": "右哼哼"},
    {"key": "yiw", "name": "疑问"},
    {"key": "yl", "name": "月亮"},
    {"key": "yun", "name": "晕"},
    {"key": "yx", "name": "阴险"},
    {"key": "zhad", "name": "炸弹"},
    {"key": "zhem", "name": "疯了"},
    {"key": "zhh", "name": "左哼哼"},
    {"key": "zhm", "name": "咒骂"},
    {"key": "zhq", "name": "转圈"},
    {"key": "zk", "name": "抓狂"},
    {"key": "zq", "name": "足球"}
];
var cc = {};
for (var i = 0; i < emojisData.length; i++) {
  var emoji = emojisData[i];
  cc[emoji.name] = emoji.key;
}

Fs.writeFileSync("emoji.json", JSON.stringify({"images": cc}));
Fs.writeFileSync("angular-emoji.css", output);
